import axios from 'axios'
//创建axios的实例
const service = axios.create({
    // baseURL:"https://www.fastmock.site/mock/f2f4024bc324da72eaac38db6b393ae6/shop/api",
    baseURL:"http://127.0.0.1:8000/api/CloudForm",
    // baseURL:"http://47.97.219.99:8018/cloudForm",
    timeout:5000,
    headers:{
        "Content-Type":"application/json;charset=utf-8"
    }
})

//请求拦截
service.interceptors.request.use((config)=>{
    config.headers=config.headers || {}
    if(localStorage.getItem('token')){
        config.headers.token = localStorage.getItem('token') || ""
    }
    return config
})

//响应拦截
service.interceptors.response.use((res)=>{
    // console.log('请求拦截')
    // console.log('res:',res.data)
    // console.log('res.data:',res.data)
    // console.log('res.data.data',res.data.data)
    // console.log('res.data.code',res.data.code)
    const code = res.data.code
    if(code !== 200 ){
        console.log('code is no 200')
        return Promise.reject(res.data)
    }

    return res.data
},(err)=>{
    console.log('err',err)
})

export default service